package com.roubsite.cloud.common.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class RedisService {
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    public void putRedis(String key, Object value, long expireSeconds) {
        redisTemplate.opsForValue().set(key, value);
        redisTemplate.expire(key, expireSeconds, TimeUnit.SECONDS);
    }

    public Object getFromRedis(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public void delFromRedis(String key) {
        redisTemplate.delete(key);
    }
}
